;; collection/symbol.scm - (c) rohan drape, 2000-2005

;; `s' is a <symbol> and `f' is a <procedure> of type <string> ->
;; <string>.

(define (symbol-variant s f)
  (string->symbol (f (symbol->string s))))

;; Higher-order variant.

(define (string-op->symbol-op f)
  (lambda (s)
    (symbol-variant s f)))

;; Evaluates to a symbol that is the concatenation of the given
;; symbols.

(define (symbol-append . s)
  (string->symbol (apply string-append (map symbol->string s))))

;; template is a <string>

(define-syntax symbol-format
  (syntax-rules ()
    ((_ template argument ...)
     (string->symbol (format template argument ...)))))

;; Symbol versions of string comparison procedures.  The names follow
;; the R5RS convention and not the SRFI 1,13 convention, which omits
;; the question mark.

(define (string-cmp->symbol-cmp p) 
  (lambda (a b) (p (symbol->string a) (symbol->string b))))

(define symbol<? (string-cmp->symbol-cmp string<?))
(define symbol>? (string-cmp->symbol-cmp string>?))
(define symbol=? (string-cmp->symbol-cmp string=?))
(define symbol<=? (string-cmp->symbol-cmp string<=?))
(define symbol>=? (string-cmp->symbol-cmp string>=?))
(define symbol-tsc (string-cmp->symbol-cmp string-tsc))

